home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / scheme / scm / wb1a1.lha / wb / sys.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-29  |  5.9 KB  |  198 lines

  1. /* WB-tree File Based Associative String Data Base System.
  2.    Copyright (c) 1991, 1992, 1993 Holland Mark Martin
  3.  
  4. Permission to use, copy, modify, and distribute this software and its
  5. documentation for educational, research, and non-profit purposes and
  6. without fee is hereby granted, provided that the above copyright
  7. notice appear in all copies and that both that copyright notice and
  8. this permission notice appear in supporting documentation, and that
  9. the name of Holland Mark Martin not be used in advertising or
  10. publicity pertaining to distribution of the software without specific,
  11. written prior consent in each case.  Permission to incorporate this
  12. software into commercial products can be obtained from Jonathan
  13. Finger, Holland Mark Martin, 174 Middlesex Turnpike, Burlington, MA,
  14. 01803-4467, USA.  Holland Mark Martin makes no representations about
  15. the suitability or correctness of this software for any purpose.  It
  16. is provided "as is" without express or implied warranty.  Holland Mark
  17. Martin is under no obligation to provide any services, by way of
  18. maintenance, update, or otherwise. */
  19.  
  20. #ifdef __STDC__
  21. #define STDC_INCLUDES
  22. #endif
  23. #ifdef __TURBOC__
  24. #define MSDOS
  25. #endif
  26. #ifdef MSDOS
  27. #define STDC_INCLUDES
  28. #endif
  29. #ifdef VMS
  30. #define STDC_INCLUDES
  31. #endif
  32.  
  33. #ifdef STDC_INCLUDES
  34. #include <stdlib.h>
  35. #include <string.h>
  36. #else
  37.     unsigned char *malloc();
  38.     unsigned char *realloc();
  39. #endif
  40.  
  41. #ifdef MSDOS
  42. #include <sys\types.h>
  43. #include <sys\stat.h>
  44. #include <io.h>
  45. #include <errno.h>
  46. #include <fcntl.h>
  47. # define open_input_file(name) (open(name,O_BINARY | O_RDONLY))
  48. # define open_output_file(name) (open(name,O_BINARY | O_WRONLY | O_CREAT, S_IWRITE | S_IREAD))
  49. # define open_io_file(name) (open(name,O_BINARY | O_RDWR))
  50. #else /* MSDOS */
  51. /* #include <sys/stat.h> */
  52. # define max(a,b)         (a<b ? b : a)
  53. # define min(a,b)         (a>b ? b : a)
  54. extern int errno;
  55. # define open_input_file(name) (open(name,0))
  56. # define open_output_file(name) (creat(name, 0666)) /* was S_IWRITE | S_IREAD */
  57. # define open_io_file(name) (open(name,2))
  58. #endif
  59.  
  60. #include <time.h>
  61. #define get_universal_time() time(0L)
  62.  
  63. #define substring_move_left(src,start,end,dst,dstart) (memmove(&dst[dstart],&src[start],(end)-(start)))
  64.  
  65. #define substring_move_right substring_move_left
  66.  
  67. #define substring_move(src,start,end,dst,dstart) (memcpy(&dst[dstart],&src[start],(end)-(start)))
  68.  
  69. /* these are only used in blkio.scm, but are here for their SCM equivalents. */
  70.  
  71. #define file_position(fildes) (tell(fildes))
  72. #define file_set_position(fildes,offset) (lseek(fildes,offset,0))
  73. #define write_string(fildes,buffer,nbytes) (write(fildes,(char *)buffer,nbytes))
  74. #define read_string(fildes,buffer,nbytes) (read(fildes,(char *)buffer,nbytes))
  75.  
  76. #define close_io_port(fildes) (close(fildes))
  77.  
  78. #define close_output_port(fildes) (close(fildes))
  79.  
  80. #define close_input_port(fildes) (close(fildes))
  81.  
  82. #define output_port_P(fildes) ((fildes)>=0)
  83.  
  84. #define input_port_P(fildes) ((fildes)>=0)
  85.  
  86.  
  87. struct slck {struct slck *NEXT; int FLG; int NAME;};
  88.  
  89. typedef struct slck LCK;
  90.  
  91. extern LCK *last_lck;
  92.  
  93. LCK *make_lck();
  94.  
  95. int try_lck();
  96.  
  97. void lck();
  98.  
  99. void unlck();
  100.  
  101. void check_lcks();
  102.  
  103. struct entry {struct entry *NEXT;long ID;unsigned char *BLK;int TAG, AGE, DTY, PUS, ACC, REF, SEG;};
  104.  
  105. typedef struct entry ENTRY;
  106.  
  107. typedef int (*int_function)();
  108.  
  109. ENTRY *make_ent();
  110.  
  111. #define ent_tag(ent) ((ent)->TAG)
  112. #define ent_next(ent) ((ent)->NEXT)
  113. #define ent_seg(ent) ((ent)->SEG)
  114. #define ent_id(ent) ((ent)->ID)
  115. #define ent_blk(ent) ((ent)->BLK)
  116. #define ent_age(ent) ((ent)->AGE)
  117. #define ent_dty_P(ent) ((ent)->DTY)
  118. #define ent_pus(ent) ((ent->PUS))
  119. #define ent_acc(ent) ((ent)->ACC)
  120. #define ent_ref(ent) ((ent)->REF)
  121.  
  122. #define ent_set_tag(ent, tag) {(ent)->TAG = tag;}
  123. #define ent_set_next(ent, next) {(ent)->NEXT = next;}
  124. #define ent_set_seg(ent, seg) {(ent)->SEG = seg;}
  125. #define ent_set_id(ent, num) {(ent)->ID = num;}
  126. #define ent_set_age(ent, age) {(ent)->AGE = age;}
  127. #define ent_set_dty(ent, dty) {(ent)->DTY = dty;}
  128. #define ent_set_pus(ent, pus) {(ent)->PUS = pus;}
  129. #define ent_set_acc(ent, acc) {(ent)->ACC = acc;}
  130. #define ent_set_ref(ent, ref) {(ent)->REF = ref;}
  131.  
  132. typedef struct {int SEG, TYP;long ID, LAST; int WCB, SPARE;} HAND;
  133.  
  134. HAND *make_han();
  135.  
  136. #define han_id(han) (((HAND *)(han))->ID)
  137. #define han_seg(han) (((HAND *)(han))->SEG)
  138. #define han_typ(han) (((HAND *)(han))->TYP)
  139. #define han_last(han) (((HAND *)(han))->LAST)
  140. #define han_wcb(han) (((HAND *)(han))->WCB)
  141.  
  142. #define han_set_num(han,num) {((HAND *)(han))->ID = num;}
  143. #define han_set_seg(han,seg) {((HAND *)(han))->SEG = seg;}
  144. #define han_set_typ(han,typ) {((HAND *)(han))->TYP = typ;}
  145. #define han_set_last(han,last) {((HAND *)(han))->LAST = last;}
  146. #define han_set_wcb(han,wcb) {((HAND *)(han))->WCB = wcb;}
  147.  
  148. typedef struct {
  149.   int PORT, BSIZ;
  150.   long USED;
  151.   unsigned char *STRN;
  152.   HAND RT_HAN, FL_HAN;
  153.   LCK FLCK;
  154.   LCK FFCK;
  155.   int FLC_LEN;
  156.   long *FLC;
  157. } SEGD;
  158.  
  159. extern SEGD segd_tab[];
  160.  
  161. #define segd_port(segd) ((segd).PORT)
  162. #define segd_bsiz(segd) ((segd).BSIZ)
  163. #define segd_used(segd) ((segd).USED)
  164. #define segd_str(segd) ((segd).STRN)
  165. #define segd_rt_han(segd) (&((segd).RT_HAN))
  166. #define segd_fl_han(segd) (&((segd).FL_HAN))
  167. #define segd_lck(segd) (&((segd).FLCK))
  168. #define segd_fck(segd) (&((segd).FFCK))
  169. #define segd_flc_len(segd) ((segd).FLC_LEN)
  170. #define segd_flc(segd) ((segd).FLC)
  171.  
  172. #define segd_set_port(segd,port) {(segd).PORT = port;}
  173. #define segd_set_bsiz(segd,bsiz) {(segd).BSIZ = bsiz;}
  174. #define segd_set_used(segd,used) {(segd).USED = used;}
  175. #define segd_set_str(segd,strn) {(segd).STRN = strn;}
  176. #define segd_set_flc_len(segd,len) {(segd).FLC_LEN = len;}
  177. #define segd_set_flc(segd,flc) {(segd).FLC = flc;}
  178.  
  179. #include <stdio.h>
  180.  
  181. extern FILE *diagout;
  182.  
  183. #include "../wb/defs.h"
  184. #include "../wb/ent.h"
  185. #include "../wb/blink.h"
  186. #include "../wb/handle.h"
  187. #include "../wb/prev.h"
  188. #include "../wb/del.h"
  189. #include "../wb/stats.h"
  190. #include "../wb/blkio.h"
  191. #include "../wb/scan.h"
  192.  
  193. /* BLK predicates */
  194.  
  195. #define root_P(blk) (*(long *)&blk[blk_id_pos] == *(long *)&blk[blk_top_id_pos])
  196.  
  197. #define end_of_chain_P(blk) (*(long *)&blk[blk_nxt_id_pos] == 0L)
  198.